<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv=”X-UA-Compatible” content=”IE=edge″/>
    <title>页面</title>
    <script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/loading.js"></script>
    <link href="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/theme-chalk/index.css" rel="stylesheet">

</head>
<style>
    .el-input {
        width: 100%;
    }

    .el-select {
        width: 100%;
    }
    .el-input--small .el-input__inner {
        height: 25px;
        line-height: 32px;
    }

    .el-button--small, .el-button--small.is-round {
        padding: 5px 10px;
    }
</style>
<body>
<div id="app">
    <el-container v-show="show=='list'">
        <el-header>
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">数据中心</el-breadcrumb-item>
                <el-breadcrumb-item>SPU库</el-breadcrumb-item>
            </el-breadcrumb>
        </el-header>
        <el-header>

            <el-row>
                <a href="/dataCenter/spuAdd.page">
                    <el-col :xs="8" :sm="8" :md="4" :lg="2" :xl="2">
                        <el-button type="primary" icon="el-icon-edit" :offset="6">新增</el-button>
                    </el-col>
                </a>
                <el-col :xs="14" :sm="14" :md="8" :lg="8" :xl="8">
                    <el-input placeholder="请输入内容" @keyup.enter.native="enterSearch" v-model="keySearch"
                              style="width: 100%">
                        <el-button slot="append" icon="el-icon-search" @click=search></el-button>
                    </el-input>
                </el-col>
            </el-row>
        </el-header>
        <el-main>
            <el-table v-loading="dataLoading" :data="tableData" stripe border style="width:100%" highlight-current-row
                      size="mini" tooltip-effect="dark" height="calc(100vh - 240px)"
            >
                　　
                <el-table-column label="序号" align="center" width="50px">
                    　　
                    <template scope="scope"><span>{{scope.$index+(currentPage - 1) * pageSize + 1}}</span></template>
                </el-table-column>
                <el-table-column prop="spu_code" label="SPU编号" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
                　　
                <el-table-column prop="spu_name" label="SPU名称" align="center" :show-overflow-tooltip=true>
                    　　
                </el-table-column>
            <#--<el-table-column prop="spu_unit" label="单位" align="center" :show-overflow-tooltip=true>-->
            <#--　　-->
            <#--</el-table-column>-->
            <#--　　-->
            <#--<el-table-column prop="spu_brand" label="品牌" align="center" :show-overflow-tooltip=true>-->
            <#--　　-->
            <#--</el-table-column>-->
            <#--<el-table-column prop="spu_model" label="系列/型号" align="center" :show-overflow-tooltip=true>-->
            <#--　　-->
            <#--</el-table-column>-->
            <#--<el-table-column prop="spu_spec_name_set" label="规格" align="center" :show-overflow-tooltip=true>-->
            <#--　　-->
            <#--</el-table-column>-->
                <el-table-column label="操作" align="center" min-width="140px" fixed="right">
                    <template slot-scope="scope">
                        <el-button @click="detail(scope.row.spu_code)" type="text">查看</el-button>
                        <el-button type="text" @click="modify(scope.row.spu_code)">编辑</el-button>
                        <el-button type="text" @click="cancel(scope.row.spu_code)">作废</el-button>
                    </template>
                </el-table-column>

            </el-table>
        </el-main>
        <el-footer>
            <el-row>
                <el-col>
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                   :page-sizes="[100, 500, 1000]" :page-size="pageSize"
                                   layout="total, sizes, prev, pager, next, jumper"
                                   :total="totalRecords">
                    </el-pagination>
                </el-col>
            </el-row>
        </el-footer>
    </el-container>
    <el-container v-show="show=='detail'">
        <el-header>
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">数据中心</el-breadcrumb-item>
                <el-breadcrumb-item>SPU库</el-breadcrumb-item>
                <el-breadcrumb-item>SPU查看</el-breadcrumb-item>
            </el-breadcrumb>
        </el-header>
        <el-main>
            <el-form ref="SPU" :model="SPU" label-width="20%">
                <el-row>
                    <el-col :xs="22" :sm="16" :md="10" :lg="10" :xl="10">
                        <el-form-item label="SPU编号" prop="spu_code">
                            <el-input v-model="SPU.spu_code" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="22" :sm="16" :md="10" :lg="10" :xl="10">
                        <el-form-item label="SPU名称" prop="spu_name">
                            <el-input v-model="SPU.spu_name" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="10" :lg="10" :xl="10">-->
            <#--<el-form-item label="单位" prop="spu_unit">-->
            <#--<el-input v-model="SPU.spu_unit" :disabled="true" ></el-input>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--<el-col :xs="22" :sm="16" :md="10" :lg="10" :xl="10">-->
            <#--<el-form-item label="品牌" prop="spu_brand">-->
            <#--<el-input v-model="SPU.spu_brand" :disabled="true" ></el-input>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="10" :lg="10" :xl="10">-->
            <#--<el-form-item label="系列/型号" prop="spu_model">-->
            <#--<el-input v-model="SPU.spu_model" :disabled="true" ></el-input>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--<el-col :xs="22" :sm="16" :md="10" :lg="10" :xl="10">-->
            <#--<el-form-item label="规格" prop="spu_spec_name_set">-->
            <#--<el-input v-model="SPU.spu_spec_name_set" :disabled="true" ></el-input>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="10" :lg="10" :xl="10">-->
            <#--<el-form-item label="描述" prop="spu_content">-->
            <#--<el-input v-model="SPU.spu_content" :disabled="true" ></el-input>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--<el-col :xs="22" :sm="16" :md="10" :lg="10" :xl="10">-->
            <#--<el-form-item label="SPU族URL" prop="spu_family_url">-->
            <#--<el-input v-model="SPU.spu_family_url" :disabled="true" ></el-input>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
                <el-row>
                    <el-col :xs="22" :sm="16" :md="10" :lg="10" :xl="10">
                        <el-form-item label="图片" prop="spu_pic_url">
                            <img :src="SPU.spu_pic_url" style="max-width:100px">
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :xs="8" :sm="8" :md="4" :lg="2" :xl="2">
                        <el-button type="primary" icon="el-icon-upload"  @click="importSku">绑定SKU</el-button>
                    </el-col>
                    <el-col :xs="14" :sm="14" :md="8" :lg="8" :xl="8">
                        <el-input placeholder="请输入内容" v-model="demoSearch" >
                            <el-button slot="append" icon="el-icon-search"></el-button>
                        </el-input>
                    </el-col>
                </el-row>
                <el-table :data="tables.slice((table.pageIndex-1)*table.pageSize,table.pageIndex*table.pageSize)"
                          v-loading="tableLoading" class="tb-edit" style="width: 100%" highlight-current-row
                          @row-click="handleCurrentChange" size="mini" border height="calc(100vh - 417px)">
                    <el-table-column label="SKU编号" prop="sku_code" :show-overflow-tooltip=true>
                    <#--<template scope="scope">-->
                    <#--<el-input size="small" v-model="scope.row.sku_code" :disabled="true"></el-input>-->
                    <#--</template>-->
                    </el-table-column>
                    <el-table-column label="SKU名称" prop="sku_name" :show-overflow-tooltip=true>
                    <#--<template scope="scope">-->
                    <#--<el-input size="small" v-model="scope.row.sku_name" :disabled="true"></el-input>-->
                    <#--</template>-->
                    </el-table-column>
                    <el-table-column label="品牌" prop="sku_brand" :show-overflow-tooltip=true>
                    <#--<template scope="scope">-->
                    <#--<el-input size="small" v-model="scope.row.sku_brand" :disabled="true"></el-input>-->
                    <#--</template>-->
                    </el-table-column>
                    <el-table-column label="单位" prop="sku_unit" :show-overflow-tooltip=true>
                    <#--<template scope="scope">-->
                    <#--<el-input size="small" v-model="scope.row.sku_unit" :disabled="true"></el-input>-->
                    <#--</template>-->
                    </el-table-column>
                    <el-table-column label="型号" prop="sku_model" :show-overflow-tooltip=true>
                    <#--<template scope="scope">-->
                    <#--<el-input size="small" v-model="scope.row.sku_unit" :disabled="true"></el-input>-->
                    <#--</template>-->
                    </el-table-column>
                    <el-table-column label="规格参数" prop="sku_slug_set" :show-overflow-tooltip=true>
                    <#--<template scope="scope">-->
                    <#--<el-input size="small" v-model="scope.row.sku_slug_set" :disabled="true"></el-input>-->
                    <#--</template>-->
                    </el-table-column>
                    <el-table-column label="SKU成本价格" prop="sku_cost_price" :show-overflow-tooltip=true>
                    <#--<template scope="scope">-->
                    <#--<el-input size="small" v-model="scope.row.sku_cost_price" :disabled="true"></el-input>-->
                    <#--</template>-->
                    </el-table-column>
                    <el-table-column label="SKU官方价格" prop="sku_official_price" :show-overflow-tooltip=true>
                    <#--<template scope="scope">-->
                    <#--<el-input size="small" v-model="scope.row.sku_official_price" :disabled="true"></el-input>-->
                    <#--</template>-->
                    </el-table-column>
                    <el-table-column label="操作" width="150">
                        <template scope="scope">
                            <el-button size="small" type="danger"
                                       @click="handleDelete(scope.$index, scope.row.sku_code)">解绑
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                        @size-change="SizeChange"
                        @current-change="CurrentChange"
                        :current-page="table.pageIndex"
                        :page-sizes="[100, 500, 1000]"
                        :page-size="table.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="tables.length">
                </el-pagination>
                <el-form-item>
                    <el-button @click="detailBack">返回</el-button>
                </el-form-item>
            </el-form>
        </el-main>
        <el-dialog title="请选择SKU" :visible.sync="dialogFormVisible" :fullscreen="true">
            <el-input v-on:input="inputFunc" v-model="SKU.keySearch" placeholder="请输入搜索内容" style="width:80%">
                <el-button slot="append" icon="el-icon-search" @click=skuSearch></el-button>
            </el-input>
            <el-table v-loading="SKULoading" ref="SKU.multipleTable" :data="SKU.tableData" tooltip-effect="dark"
                      style="width: 100%"
                      @selection-change="handleSelectionChange" size="mini">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="sku_name" label="SKU名称" :show-overflow-tooltip=true>
                </el-table-column>
                <el-table-column prop="sku_code" label="SKU编码" :show-overflow-tooltip=true>
                </el-table-column>
                <el-table-column prop="sku_brand" label="品牌" :show-overflow-tooltip=true>
                </el-table-column>
                <el-table-column prop="sku_unit" label="单位" :show-overflow-tooltip=true>
                </el-table-column>
                <el-table-column prop="sku_model" label="型号" :show-overflow-tooltip=true>
                </el-table-column>
                <el-table-column prop="sku_slug_set" label="规格参数" :show-overflow-tooltip=true>
                </el-table-column>
                <el-table-column prop="sku_cost_price" label="sku价格" :show-overflow-tooltip=true>
                </el-table-column>
                <el-table-column prop="sku_official_price" label="sku成本价格" :show-overflow-tooltip=true>
                </el-table-column>
            </el-table>
            <el-pagination @current-change="skuCurrentPage" :current-page.sync="SKU.page"
                           :page-sizes="[100, 500, 1000]" :page-size="SKU.limit"
                           layout="prev, pager, next" :total="SKU.total">
            </el-pagination>
            <div slot="footer" class="dialog-footer">
                <el-button @click="checkCancel">取 消</el-button>
                <el-button type="primary" @click="checkOK">确 定</el-button>
            </div>
        </el-dialog>
    </el-container>
    <el-container v-show="show=='update'">
        <el-header>
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">数据中心</el-breadcrumb-item>
                <el-breadcrumb-item>SPU库</el-breadcrumb-item>
                <el-breadcrumb-item>SPU修改</el-breadcrumb-item>
            </el-breadcrumb>
        </el-header>
        <el-main>
            <el-form ref="SPU" :model="SPU" label-width="20%">
                <el-row>
                    <el-col :xs="22" :sm="16" :md="12" :lg="12" :xl="8">
                        <el-form-item label="SPU编号" prop="spu_code">
                            <el-input :disabled="true" v-model="SPU.spu_code" style="width: 50%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :xs="22" :sm="16" :md="12" :lg="12" :xl="8">
                        <el-form-item label="SPU名称" prop="spu_name">
                            <el-input v-model="SPU.spu_name" style="width: 50%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="12" :lg="12" :xl="8">-->
            <#--<el-form-item label="单位" prop="spu_unit_id">-->
            <#--<el-select v-model="SPU.spu_unit_id" filterable placeholder="请选择单位" style="width: 50%">-->
            <#--<el-option v-for="unit in unitList" :key="unit.id" :label="unit.unit_name"-->
            <#--:value="unit.id">-->
            <#--</el-option>-->
            <#--</el-select>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="12" :lg="12" :xl="8">-->
            <#--<el-form-item label="品牌" prop="spu_brand_id">-->
            <#--<el-select v-model="SPU.spu_brand_id" filterable placeholder="请选择品牌" style="width: 50%">-->
            <#--<el-option v-for="brand in brandList" :key="brand.id"-->
            <#--:label="brand.brand_name"-->
            <#--:value="brand.id">-->
            <#--</el-option>-->
            <#--</el-select>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="12" :lg="12" :xl="8">-->
            <#--<el-form-item label="系列/型号" prop="spu_model">-->
            <#--<el-input v-model="SPU.spu_model" style="width: 50%"></el-input>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="12" :lg="12" :xl="8">-->
            <#--<el-form-item label="描述" prop="spu_content">-->
            <#--<el-input v-model="SPU.spu_content" style="width: 50%"></el-input>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="12" :lg="12" :xl="8">-->
            <#--<el-form-item label="SPU族URL" prop="spu_family_url">-->
            <#--<el-input v-model="SPU.spu_family_url" style="width: 50%"></el-input>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="12" :lg="12" :xl="8">-->
            <#--<el-form-item label="规格">-->
            <#--<el-button @click="addDomain">新增规格</el-button>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
            <#--<el-row>-->
            <#--<el-col :xs="22" :sm="16" :md="12" :lg="12" :xl="8">-->
            <#--<el-form-item v-for="-->
            <#--(domain, index) in SPU.spuSpecList"-->
            <#--:label="'规格' + (index+1)" :prop="'spuSpecList.' + index + '.spec'">-->
            <#--<el-select v-model="domain.spec" filterable placeholder="请选择规格" style="width: 40%">-->
            <#--<el-option v-for="spec in specList" :key="spec.id.toString()" :label="spec.spec_name"-->
            <#--:value="spec.id.toString()">-->
            <#--</el-option>-->
            <#--</el-select>-->
            <#--<el-button @click.prevent="removeDomain(domain)">删除</el-button>-->
            <#--</el-form-item>-->
            <#--</el-col>-->
            <#--</el-row>-->
                <el-row>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                        <el-form-item label="图片" prop="SPU.spu_pic_url">
                            <img :src="SPU.spu_pic_url" style="max-width:100px;max_height:100px">
                            <el-upload ref="upload" class="upload-demo" accept=".jpeg,.png,.gif"
                                       action="${url}/uploadController/upload.json" :before-upload="beforeAvatarUpload"
                                       :on-success="handleAvatarSuccess" :on-remove="handleRemove" :on-exceed="onExceed"
                                       multiple :limit="1" list-type="picture-card">
                                <el-button size="small" type="primary">点击上传</el-button>
                            </el-upload>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="submit('SPU')">提交</el-button>
                    <el-button @click="modifyBack">返回</el-button>
                </el-form-item>
            </el-form>
        </el-main>
    </el-container>
</div>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/dist/vue.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/index.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/publiccss/assets/global/plugins/jquery.min.js"
        type="text/javascript"></script>
<script>
    new Vue({
        el: '#app',
        data: function () {
            return {
                SKULoading: false,
                tableLoading: false,
                dataLoading: false,
                table: {
                    pageSize: 100,
                    pageIndex: 1,
                    // total:0,
                },
                rules: {
                    spu_code: [{
                        required: true,
                        message: '请输入SPU编号',
                        trigger: 'blur'
                    }],
                    spu_name: [{
                        required: true,
                        message: '请输入SPU名称',
                        trigger: 'blur'
                    }],
                    // spu_brand_id: [{
                    //     required: true,
                    //     message: '请选择品牌',
                    //     trigger: 'change'
                    // }],
                    // spu_unit_id: [{
                    //     required: true,
                    //     message: '请选择单位',
                    //     trigger: 'change'
                    // }]
                },
                tableData: [],
                currentPage: 1, //当前页
                pageSize: 100, //每页总数
                totalRecords: 0, //总条数
                keySearch: '',
                show: "list",
                SPU: {},
                // brandList: [],
                // unitList: [],
                // specList: [],
                // spuSpecList: [],
                dialogFormVisible: false,
                SKU: {
                    skuList: [],
                    page: 1,
                    limit: 100,
                    total: 0,
                    keySearch: '',
                    multipleSelection: [],
                    tableData: [],
                    spuCode: '',
                },
                demoSearch: '',
                demoTable: [],

            };

        },
        computed: {
            tables() {
                var search = this.demoSearch;
                if (search) {
                    return  this.SKU.skuList.filter((data) => {
                        return Object.keys(data).some((key) => {
                            //搜索所有的内容
                            return String(data[key]).toLowerCase().indexOf(search) > -1;
                        })
                    })
                }
                return this.SKU.skuList;
            }
        },
        methods: {
            SizeChange(val) {
                this.table.pageSize = val
            },
            CurrentChange(val) {
                this.table.pageIndex = val
            },

            //鼠标监听input框事件
            inputFunc($event) {
                this.keySearch = $event;
                this.SKU.page=1;
                this.SKU.limit=100;
                this.getSkuList();
            },
            //点击事件获取输入内容
            skuSearch() {
                this.SKU.page=1;
                this.SKU.limit=100;
                this.getSkuList();
            },
            getSkuList() {
                this.SKULoading = true;
                var page = this.SKU.page;
                var pageSize = this.SKU.limit;
                var key = this.SKU.keySearch;
                // var slugIdSet=this.SPU.spu_spec_set;
                // console.log(slugIdSet);
                var total = 0;
                var skuList = '';
                var boolean = false;
                $.ajax({
                    url: "${url}/sku/list.json?page=" + page + "&limit=" + pageSize +
                    "&key=" + key,
                    type: "GET",
                    // async: false,
                    dataType: "json",
                    success: (data) => {
                        this.SKULoading = false;
                        if (data.ret) {
                            this.SKU.tableData = data.data;
                            this.SKU.total = data.count;
                        } else {
                            this.$message.error('请求异常');
                        }
                    }
                });

            },
            importSku() {
                this.dialogFormVisible = true;
                this.getSkuList();
            },

            checkOK() {
                this.dialogFormVisible = false;
                var skuCodeList = [];
                this.SKU.multipleSelection.forEach(function (ele) {
                    skuCodeList.push(ele.sku_code);
                });
                var spuCode = this.SKU.spuCode;
                var boolean = false;
                var msg = '';
                $.ajax({
                    url: "${url}/spuRelateSku/spuRelateSku.json",
                    type: "POST",
                    data: {
                        spuCode: spuCode,
                        beChecked: skuCodeList.toString()
                    },
                    async: false,
                    success: function (result) {
                        boolean = result.ret;
                        if (!boolean) {
                            msg = result.msg;
                        }
                    }
                });
                if (boolean) {
                    this.$message({
                        type: 'success',
                        message: '绑定成功',
                        duration: 6000
                    });
                    this.SKU.skuList = this.SKU.skuList.concat(this.SKU.multipleSelection);
                } else {
                    this.$message.error(msg);
                }
            },
            checkCancel() {
                this.dialogFormVisible = false;
                this.SKU.multipleSelection = [];
            },
            skuCurrentPage(val) {
                this.getSkuList();
            },
            handleSelectionChange(val) {
                this.SKU.multipleSelection = val;
            },
            handleCurrentChange(row, event, column) {
                console.log(row, event, column, event.currentTarget)
            },
            handleDelete(index, sku_code) {
                var spuCode = this.SKU.spuCode;
                this.$confirm('此操作将永久解除此关联关系, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    var boolean = false;
                    $.ajax({
                        url: "${url}/spuRelateSku/deleteRelate.json",
                        type: "get",
                        data: {skuCode: sku_code, spuCode: spuCode},
                        // dataType: "json",
                        async: false,
                        success: function (result) {
                            boolean = result.ret;
                        }
                    });
                    if (boolean) {
                        this.$message({
                            type: 'success',
                            message: '解绑成功',
                            duration: 6000
                        });
                        this.SKU.skuList.splice(index, 1);
                    } else {
                        this.$message.error('解绑失败');
                    }
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
            onExceed(files, fileList) {
                this.$message({
                    type: 'info',
                    message: '最多只能上传一个图片',
                    duration: 6000
                });
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handleAvatarSuccess(data, file) {
                if (data.ret) {
                    this.SPU.spu_pic_url = data.data.data;
                }
            },
            beforeAvatarUpload(file) {
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isLt2M) {
                    this.$message.error('图片大小不能超过 2MB!');
                }
                return isLt2M;
            },
            submit: function (formName) {
                var SPU = this.SPU;
                // var specSlugSet = [];
                // var arr = this.spuSpecList;
                // for(i=0;i<arr.length;i++){
                //     console.log("-------"+arr[i].spec);
                //     specSlugSet.push(arr[i].spec);
                // }
                // this.spuSpecList.forEach(function (ele) {
                //     if (ele.spec.length > 0) {
                //         specSlugSet.push(ele.spec);
                //     }
                // });

                // SPU.spu_spec_set = specSlugSet.toString();
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        var boolean = false;
                        var msg = '';
                        $.ajax({
                            url: "${url}/spu/updateSpu.json",
                            type: "POST",
                            async: false,
                            data: SPU,
                            success: function (result) {
                                boolean = result.ret;
                                if (!boolean) {
                                    msg = result.msg;
                                }
                            }
                        });
                        if (boolean) {
                            this.$message({
                                message: '修改成功',
                                type: 'success'
                            });
                            setTimeout(function () {
                                window.location.href = "/dataCenter/spuIndex.page";
                            }, 1000);
                        } else {
                            this.$message.error(msg);
                        }
                    } else {
                        this.$message({
                            message: '警告，请填写必填字段',
                            type: 'warning'
                        });
                        return false;
                    }
                });
            },
            // removeDomain(item) {
            //     var index = this.spuSpecList.indexOf(item)
            //     if (index !== -1) {
            //         this.spuSpecList.splice(index, 1)
            //     }
            // },
            // addDomain() {
            //     this.spuSpecList.push({
            //         spec: '',
            //     });
            // },
            detailBack: function () {
                this.SKU.multipleSelection = [];
                this.show = 'list';
            },
            modifyBack: function () {
                this.$refs.upload.clearFiles();
                this.show = 'list';
            },
            //查看
            detail: function (spu_code) {
                this.tableLoading = true;
                this.SKU.spuCode = spu_code;
                var SPU = this.SPU;
                var boolean = false;
                $.ajax({
                    url: '${url}/spu/detailSpu.json',
                    data: {
                        spu_code: spu_code
                    },
                    type: 'get',
                    // async: false,
                    dataType: 'json',
                    success: (result) => {
                        this.tableLoading = false;
                        if (result.ret) {
                            SPU = result.data;
                            this.SPU = SPU;
                            this.SKU.skuList = this.SPU.sku_list;
                        } else {
                            this.$message.error('请求异常');
                        }
                    }
                });
                this.show = 'detail';
            },
            // //修改
            modify: function (spu_code) {
                // this.unitAjax();
                // this.brandAjax();
                // this.specAjax();
                this.detail(spu_code);
                // this.spuSpecList = this.SPU.spuSpecList;
                this.show = 'update';
            },
        <#--//获取品牌列表-->
        <#--brandAjax: function () {-->
        <#--var boolean = false;-->
        <#--var brandList = [];-->
        <#--$.ajax({-->
        <#--url: '${url}/dataDicController/BrandList.json',-->
        <#--data: {-->
        <#--page: 0,-->
        <#--param: null,-->
        <#--limit: 0-->
        <#--},-->
        <#--type: 'get',-->
        <#--async: false,-->
        <#--dataType: 'json',-->
        <#--success: function (result) {-->
        <#--boolean = result.ret;-->
        <#--if(boolean){-->
        <#--brandList = result.data;-->
        <#--}-->

        <#--}-->
        <#--});-->
        <#--if (boolean) {-->
        <#--this.brandList = brandList;-->
        <#--}else{-->
        <#--this.$message.error('品牌列表请求异常');-->
        <#--}-->
        <#--},-->
        <#--//获取单位列表-->
        <#--unitAjax: function () {-->
        <#--var boolean = false;-->
        <#--var unitList = [];-->
        <#--$.ajax({-->
        <#--url: '${url}/dataDicController/unitList.json',-->
        <#--data: {-->
        <#--page: 0,-->
        <#--param: null,-->
        <#--limit: 0-->
        <#--},-->
        <#--type: 'get',-->
        <#--async: false,-->
        <#--dataType: 'json',-->
        <#--success: function (result) {-->
        <#--boolean = result.ret;-->
        <#--if(boolean){-->
        <#--unitList = result.data;-->
        <#--}-->
        <#--}-->
        <#--});-->
        <#--if (boolean) {-->
        <#--this.unitList = unitList;-->
        <#--}else{-->
        <#--this.$message.error('单位列表请求异常');-->
        <#--}-->
        <#--},-->
        <#--//获取规格属性列表-->
        <#--specAjax: function () {-->
        <#--var boolean = false;-->
        <#--var specList = [];-->
        <#--$.ajax({-->
        <#--url: '${url}/dataDicController/specList.json',-->
        <#--data: {-->
        <#--page: 1,-->
        <#--param: null,-->
        <#--limit: 1000000-->
        <#--},-->
        <#--type: 'get',-->
        <#--async: false,-->
        <#--dataType: 'json',-->
        <#--success: function (result) {-->
        <#--boolean = result.ret;-->
        <#--if(boolean){-->
        <#--specList = result.data;-->
        <#--}-->
        <#--}-->
        <#--});-->
        <#--if (boolean) {-->
        <#--this.specList = specList;-->
        <#--}else{-->
        <#--this.$message.error('规格列表请求异常');-->
        <#--}-->
        <#--},-->
            //回车监听事件获取输入内容
            enterSearch: function (event) {
                this.currentPage=1;
                this.pageSize=100;
                this.keySearch = event.target.value;
                this.ajaxFunction()
            },
            //点击事件获取输入内容
            search: function () {
                this.currentPage=1;
                this.pageSize=100;
                this.ajaxFunction()
            },
            //作废
            cancel: function (spu_code) {
                this.$confirm('此操作将永久作废该SPU, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    var boolean = false;
                    $.ajax({
                        url: '${url}/spu/cancelSpu.json',
                        type: 'POST',
                        data: {
                            spu_code: spu_code
                        },
                        async: false,
                        dataType: 'json',
                        success: function (result) {
                            boolean = result.ret;
                        }
                    });
                    if (boolean) {
                        this.ajaxFunction();
                        this.$message({
                            type: 'success',
                            message: '操作成功!'
                        });
                    } else {
                        this.$message.error('操作失败');
                    }
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
            handleSizeChange: function (val) {
                this.pageSize = val;
                this.ajaxFunction()
            },
            handleCurrentChange: function (val) {

                this.currentPage = val;
                this.ajaxFunction()
            },
            ajaxFunction: function () {
                this.dataLoading = true;
                var page = this.currentPage;
                var limit = this.pageSize;
                var key = this.keySearch;
                var resultData = this.tableData;
                var total = this.totalRecords;
                $.ajax({
                    url: '${url}/spu/list.json',
                    type: 'get',
                    data: {
                        key: key,
                        page: page,
                        limit: limit,
                    },
                    // async: false,
                    dataType: 'json',
                    success: (result) => {
                        this.dataLoading = false;
                        if (result.ret) {
                            this.tableData = result.data;
                            this.totalRecords = result.count;
                        }
                    }
                });
            },
        },
        mounted: function () {
            this.ajaxFunction();
        },
    })
</script>

</body>

</html>